#!/usr/bin/env python
# @author   FAN Kai (fankai@net.pku.edu.cn), Peking University  
# @date     Jun 12 04:30:52 PM CST 2009

import urllib, re

def gget(filename, page):
    pat = "\?action=download&id=\d+&file=%s"%filename
    m = re.search(pat, page)
    if m:
        content = urllib.urlopen(url+m.group(0)).read()
        open(filename, 'wb'). write(content)
        print 'ok'
    else:
        print 'not found'

if __name__ == "__main__":
    import sys
    sys.stdout = sys.stderr
    url = "http://fankaicn.appspot.com/store"
    f = urllib.urlopen(url)
    page = f.read()

    for f in sys.argv[1:]:
        print "downloading %s ..."%f, 
        gget(f, page)
